﻿#pragma once

#include "byte_buffer.h"
#include <zlib.h>

namespace as
{
	namespace tools
	{
		static std::string compress(const std::string_view &data);
		static std::string decompress(const std::string_view &compressedData);

		enum PacketErr
		{
			PE_SUCCESS = 0,
			PE_HEAD_ERROR,
			PE_HEAD_TO_SMALL,
			PE_BODY_ERROR,
			PE_BODY_TOO_SMALL,
			PE_BODY_TOO_BIG,
			PE_CHECK_ERR,
			PE_MALLOC_ERR,
		};
		struct BasePacketHandle
		{
			virtual void Pack(ByteBuffer *in, ByteBuffer *out) = 0;
			virtual as::tools::PacketErr Unpack(ByteBuffer *in, ByteBuffer *out, int size) = 0;
		};

		struct NetPacketHandle : public BasePacketHandle
		{
			virtual void Pack(ByteBuffer *in, ByteBuffer *out);
			virtual as::tools::PacketErr Unpack(ByteBuffer *in, ByteBuffer *out, int size);
		};
	}
}
